<?php

namespace app\admin\validate;

use app\common\validate\tysj\Product as CommonProduct;

class Product extends CommonProduct
{
    /**
     * 验证规则
     */
    protected $rule = [
        'id'      => 'require|isPrepare',
        'remark'  => 'require|max:100'
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'id.require'      => '产品id不能为空',
        'id.isPrepare'    => '产品不是待审核状态',
        'remark.require'  => '拒绝理由不能为空',
        'remark.max'      => '拒绝理由不能超过100个字符'
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'approve'  => ['id'],
        'refuse'   => ['id', 'remark']
    ];

    protected function isPrepare($value, $rule, $data = []) {
        $row = loader('admin')->loadModel('tysj\\Product')->find($value);
        return loadEnum('ProductExamine')->isPrepare($row['examine']);
    }
    
}
